﻿//选择产品分类列表
ProcessAjaxRequest(fixUrl("api/Product/GetProductCategoryList"), "get", '', function (data) {
    for (var i = 0; i < data.length; i++) {
        $("#productCategory").append("<option value='" + data[i].ID + "'>" + data[i].Name + "</option>");
    }
})
//选择产品列表
function GetProductByCategory() {
    ProcessAjaxRequest(fixUrl("api/Product/GetActiveProductListByProductCategory"), "get", { id: $("#productCategory").val() }, function (data) {
        $("#productItem").html('');
        for (var i = 0; i < data.length; i++) {
            $("#productItem").append("<option value='" + data[i].ID + "'>" + data[i].Name + "</option>");
        }
    })
}

//省份列表
function GetProvince() {
$.ajax({
    url: fixUrl("api/Common/GetAllProvince"),
    success: function (data) {
        $(".provinceSelect ul").html("");
        for (var i = 0; i < data.length; i++) {
            $(".provinceSelect ul").append("<li> <a href='#none' data-value=" + data[i].ID + ">" + data[i].Name + "</a></li>");
        }
    }
});
}
//
function GetSelectProvinces() {
    var ids = "";
    $.each($(".provinceSelect li a.active"), function (index, item) {
        var rowData = $(item).data('value');
        ids += rowData + ",";
    })
    return ids;
}
//农作物
function AutoCompleteCrop() {
    $.getJSON(fixUrl("api/Crop/GetAllActiveCrops"), function (data) {
        var metaData = JSON.parse(data);
        //var metaData = JSON.stringify(data);
        $("#CropName").autocomplete({
            source: metaData,
            minLength: 0,
            delay: 0,
            select: function (event, ui) {
                var value = ui.item.value;
                var id = ui.item.id;
                $("#CropName").val(value);
                $("#Cropid").val(id);
                //SearchAllTrial();
            },
            change: function (event, ui) {
                $("#CropName").val((ui.item ? ui.item.value : ""));
                $("#Cropid").val((ui.item ? ui.item.id : ""))
            },
            close: function () {
                _thisComplete = false;
            },
            response: function (event, ui) {
                if (ui.content.length == 0) {
                    ui.content.push({ label: '没有匹配到任何结果', value: '' });
                }
            }
        }).focus(function () {
            $(this).autocomplete("search");
        });;
    })
}

//获取项目列表
function GetProjectCategories() {
    ProcessAjaxRequest(fixUrl("api/Trial/GetProjectCategories"), "get", "", function (data) {
        $("#projectCategory").html('');
        for (var i = 0; i < data.length; i++) {
            $("#projectCategory").append("<option value='" + data[i].ID + "'>" + data[i].Name + "</option>");
        }
    })
}
